//
//  RecruitDiliverymanViewController.m
//  Hui
//
//  Created by HawkingWang on 16/10/31.
//  Copyright © 2016年 Hui. All rights reserved.
//

#import "RecruitDiliverymanViewController.h"
#import "WebViewController.h"//网页Controller

@interface RecruitDiliverymanViewController ()

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
/**配送员姓名*/
@property (weak, nonatomic) IBOutlet UITextField *deliveryManName;
/**选择性别*/
@property (weak, nonatomic) IBOutlet UIImageView *maleImage;
@property (weak, nonatomic) IBOutlet UIImageView *femaleImage;
/**配送员联系方式*/
@property (weak, nonatomic) IBOutlet UITextField *phone;
/**配送员真实姓名*/
@property (weak, nonatomic) IBOutlet UITextField *name;
/**配送员身份证号*/
@property (weak, nonatomic) IBOutlet UITextField *identityNumber;
/**上传身份证照片*/
@property (weak, nonatomic) IBOutlet UIButton *uploadFront;
@property (weak, nonatomic) IBOutlet UILabel *frontLabel;
@property (weak, nonatomic) IBOutlet UIButton *uploadBack;
@property (weak, nonatomic) IBOutlet UILabel *backLabel;
@property (weak, nonatomic) IBOutlet UIButton *uploadHandHold;
@property (weak, nonatomic) IBOutlet UIImageView *payMarginImage;
@property (weak, nonatomic) IBOutlet UILabel *HandHoldLabel;


@end

@implementation RecruitDiliverymanViewController
{
    NSString *_sex;
    NSString *_pay;
    NSMutableArray *_uploadImageArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = YES;
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
    
    _scrollView.showsHorizontalScrollIndicator = NO;
    _sex = @"0";
    _pay = @"1";
    _uploadImageArr = [NSMutableArray arrayWithArray:@[@"0", @"0", @"0"]];
}

#pragma mark === 选择性别 ===
- (IBAction)chooseMale:(id)sender {
    _sex = @"0";
    _maleImage.image = [UIImage imageNamed:@"right-touch"];
    _femaleImage.image = [UIImage imageNamed:@"right"];
}
- (IBAction)chooseFemale:(id)sender {
    _sex = @"1";
    _maleImage.image = [UIImage imageNamed:@"right"];
    _femaleImage.image = [UIImage imageNamed:@"right-touch"];
}
#pragma mark === 上传照片 ===
- (IBAction)uploadFront:(id)sender {
    [_uploadImageArr replaceObjectAtIndex:0 withObject:@"1"];
    _frontLabel.hidden = YES;
}
- (IBAction)uploadBack:(id)sender {
    [_uploadImageArr replaceObjectAtIndex:1 withObject:@"1"];
    _backLabel.hidden = YES;
}
- (IBAction)uploadHandHold:(id)sender {
    [_uploadImageArr replaceObjectAtIndex:2 withObject:@"2"];
    _HandHoldLabel.hidden = YES;
}
#pragma mark === 保障金 ===
/**保障金勾选*/
- (IBAction)payTheMargin:(id)sender {
    if ([_pay isEqualToString:@"1"]) {
        _pay = @"0";
        _payMarginImage.image = [UIImage imageNamed:@"right"];
    }else{
        _pay = @"1";
        _payMarginImage.image = [UIImage imageNamed:@"right-touch"];
    }
}
/**保障金说明*/
- (IBAction)marginIntroduction:(id)sender {
    WebViewController *web = [[WebViewController alloc] init];
    web.titleStr = @"保障金说明";
    [self presentViewController:web animated:YES completion:nil];
}

/**配送说明*/
- (IBAction)deliveryIntroduction:(id)sender {
    WebViewController *web = [[WebViewController alloc] init];
    web.titleStr = @"配送说明";
    [self presentViewController:web animated:YES completion:nil];
}

#pragma mark === 提交 ===
- (IBAction)commit:(id)sender {
    if ([_deliveryManName.text isEqualToString:@""]) {
        [EBUtility prompt:@"请输入配送员姓名" with:self];
    }else if ([_phone.text isEqualToString:@""]){
        [EBUtility prompt:@"请输入配送员电话" with:self];
    }else if (![EBUtility isMobileNumber:_phone.text]){
        [EBUtility prompt:@"请输入正确的联系方式" with:self];
    }else if ([_name.text isEqualToString:@""]){
        [EBUtility prompt:@"请输入真实姓名" with:self];
    }else if ([_identityNumber.text isEqualToString:@""]){
        [EBUtility prompt:@"请输入身份证号" with:self];
    }else if (![EBUtility validateIdentityCard:_identityNumber.text]){
        [EBUtility prompt:@"请输入正确的身份证号" with:self];
    }else if ([_uploadImageArr[0] isEqualToString:@"0"]){
        [EBUtility prompt:@"请上传身份证正面照" with:self];
    }else if ([_uploadImageArr[1] isEqualToString:@"0"]){
        [EBUtility prompt:@"请上传身份证反面照" with:self];
    }else if ([_uploadImageArr[2] isEqualToString:@"0"]){
        [EBUtility prompt:@"请上传手持身份证照" with:self];
    }else if ([_pay isEqualToString:@"0"]){
        [EBUtility prompt:@"必须缴纳保证金才能进行申请" with:self];
    }else{
        DLog(@"提交");
        [SVProgressHUD show];
        [SVProgressHUD showSuccessWithStatus:@"提交成功"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
            [self.navigationController popViewControllerAnimated:YES];
        });
    }
}
- (IBAction)back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
